package com.carrent.demo.Controller;

import com.carrent.demo.Domain.EmployeeInformation;
import com.carrent.demo.Domain.Users;
import com.carrent.demo.Mapper.UsersMapper;
import com.carrent.demo.Service.UsersService;
import com.carrent.demo.Utils.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    UsersService usersService;

    @GetMapping("/page")
    public R getPage(Integer page,Integer pageSize,String name)
    {
        final List<Users> page1 = usersService.getPage((page - 1) * pageSize, pageSize, name);
        final Integer count = usersService.getCount(name);
        return  R.success(page1,count);

    }

    @DeleteMapping
    public  R deleteUser(@RequestParam(value = "ids") List<String> ids)
    {
        for(String s : ids)
        {
            usersService.deleteUser(s);

        }
        return R.success("");
    }

    @PutMapping
    public  R editUser(@RequestBody Users users)
    {
       usersService.editUser(users);
        return  R.success(1);
    }

    @PostMapping
    public  R addUser(@RequestBody Users users)
    {


        final Boolean aBoolean = usersService.addUser(users);
        return  R.success(aBoolean);
    }




}
